<%@page contentType="text/html;charset=utf-8"%>
<%@page import="org.springframework.context.ApplicationContext"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="com.tjtt.tdm.system.action.OrganizationAction"%>
<%@page import="com.tjtt.tdm.system.bean.Organization"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@page import="java.util.List"%>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>组织机构管理列表</title>
		<%@ include file="../jslib/jquerylib.jsp" %>
		<script type="text/javascript" src="<%=request.getContextPath() %>/jslib/lhgdialog/lhgcore.lhgdialog.min.js?skin=mac"></script>
		<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/web/style/layout.css" />
		<link rel="stylesheet" href="<%=request.getContextPath() %>/jslib/ztree/css/zTreeStyle/zTreeStyle.css" type="text/css"/>
  		<script type="text/javascript" src="<%=request.getContextPath() %>/jslib/ztree/js/jquery.ztree.core-3.5.js"></script>
  		 <script type="text/javascript" src="<%=request.getContextPath() %>/jslib/jquery.validate.min.js"></script>
	    <script type='text/javascript' src="<%=request.getContextPath() %>/jslib/jquery.form.js"></script>
	    <script type="text/javascript" src="<%=request.getContextPath() %>/jslib/additional-methods.js"></script>
		
		<!-- 结果信息返回 -->
    	<c:if test="${requestScope.message!=null}">
			<script type="text/javascript">
  	 		     alert('<c:out value="${requestScope.message}"></c:out>');
  	 		     window.close();
  			</script>
        </c:if>
		<script type="text/javascript">
			
			var treeObj;
			var flag = "1";
			var delflag = "1";
			var chaflag = "1";
			var orgParentId = "";
			var tree_sel=null;
			var old =null;
			var common_contextPath="<%=common_contextPath%>";
			var common_basePath="<%=common_basePath%>";
			var common_width = window.screen.width-0;
			var common_height = window.screen.height-405;
			$(function(){ 
			    $("#tabs").tabs({ 
			        //disabled:[1],//定义不可用元素 
			        selected:3 
			    }); 
			}) 
			//刷新
			function reload(){
				location.reload();
			}
			//查询
			function gridSearch(){
				jQuery("#gridTable").jqGrid('setGridParam',
				{
					url:"queryOrganization!queryOrganizationList.action?flag=1"
				}).trigger("reloadGrid", [{page:1}]); 
            } 
			//--查询名称 高亮 开始---------------------------------------------------------------------
			function focusKey(e) {
				if (key.hasClass("empty")) {
					key.removeClass("empty");
				}
			}
			function blurKey(e) {
				if (key.get(0).value === "") {
					key.addClass("empty");
				}
			}
			var lastValue = "", nodeList = [], fontCss = {};
			
			function searchNode(e) {
				var zTree = $.fn.zTree.getZTreeObj("tree");
				var value = $.trim(key.get(0).value);
				var keyType = "";
				keyType = "name";
				if (lastValue === value) return;
				lastValue = value;
				if (value === "") return;
				updateNodes(false);
				nodeList = zTree.getNodesByParamFuzzy(keyType, value);
				updateNodes(true);
	
			}
			function updateNodes(highlight) {
				var zTree = $.fn.zTree.getZTreeObj("tree");
				for( var i=0, l=nodeList.length; i<l; i++) {
					nodeList[i].highlight = highlight;
					zTree.updateNode(nodeList[i]);
				}
			}
			function getFontCss(treeId, treeNode) {
				return (!!treeNode.highlight) ? {color:"#A60000", "font-weight":"bold"} : {color:"#333", "font-weight":"normal"};
			}
			function filter(node) {
				return !node.isParent && node.isFirstNode;
			}
	
			var key;
			$(document).ready(function(){
				$.fn.zTree.init($("#tree"), setting, zNodes);
				key = $("#key");
				key.bind("focus", focusKey)
				.bind("blur", blurKey)
				.bind("propertychange", searchNode)
				.bind("input", searchNode); 
				var treeObj = $.fn.zTree.getZTreeObj("tree");
				var nodes = treeObj.getNodes();
				if (nodes.length>0) {
					treeObj.selectNode(nodes[0]);
					//设置选中节点后右边编辑内容的载入
					zTreeOnClick(event,"1",nodes[0],true);
				}
				
			});
			//--查询名称 高亮 结束---------------------------------------------------------------------
			//-----------------------------------
			$(document).ready(function(){
					$("#gridTableOrganization").jqGrid({
						url:common_contextPath+'/organization/queryOrganization.action?flag=1',
						datatype: "json",
						height: common_height,
						width:common_width-595,
						colNames:['主键','组织机构编号','组织机构名称','组织机构说明'],
						colModel:[
							{name:'ORG_ID',index:'ORG_ID',sorttype:"string",key:true,hidden:true,hidedlg:true}, 
							{name:'ORG_NO',index:'ORG_NO', width:160}, 
							{name:'ORG_NAME',index:'ORG_NAME', width:160}, 
							{name:'ORG_DESC',index:'ORG_DESC', width:180}
						],   
						shrinkToFit:false,
						sortname:'ORG_ID',
						sortorder:'desc',
						viewrecords:true,
						multiselect: true, // 是否显示复选框
						multiboxonly : true, 
						rownumbers: false,//显示行号
						editable:true, 
						rowNum:<%=session.getAttribute("SYS_PAGECOUNT")%>,
						rowList:[15,20,50,200,500],
						toolbar: [false,"top"],
						jsonReader: {
							root:"rows",		// 数据行（默认为：rows）
							page: "page",  	// 当前页
							total: "total",  // 总页数
							records: "records",  // 总记录数
							repeatitems : false		// 设置成false，在后台设置值的时候，可以乱序。且并非每个值都得设
						},
						prmNames:{rows:"rows",page:"page",sort:"sidx",order:"sord",search:"search"},
						pager:"#gridPagerOrganization",
						caption: "组织机构管理列表"
					});
					 jQuery("#gridTableOrganization").jqGrid('navGrid','#gridPagerOrganization',{add:false,edit:false,del:false,search:false,refresh:false});
						jQuery("#gridTableOrganization").jqGrid('navButtonAdd','#gridPagerOrganization',
							{ 	
							caption: "",                          
							title: "Reorder Columns",                           
							onClickButton : function (){                               
							jQuery("#gridTableOrganization").jqGrid('setColumns');                           
							}
						}); 
						
					$("#gridTableUsers").jqGrid({
	                    url:common_contextPath+'/organization/searchUsers.action',
	                    datatype: "json",
	                    height: common_height,
	                    width:common_width-595,
	                    colNames:['编号','用户名','姓名','性别','岗位','所属组织','用户状态','锁定状态'],
	                    colModel:[
	                        {name: 'userid', index: 'userid',width:10, sorttype:"int",hidden:true,hidedlg:true},
	                        {name: 'loginname', index: 'loginname', width:100},
	                        {name: 'username', index: 'username', width:60},
	                        {name: 'sexLabel', index: 'sex', width:50,hidden:true},
	                        {name: 'jobName', index: 'jobName', width:210}, 
	                        {name: 'organization.orgName', index: 'organization.orgName', width:80}, 
	                        {name: 'activeLabel', index: 'active', width:75},
	                        {name: 'lockFlagLabel', index: 'lockFlag', width:60}
	                    ],   
	                    shrinkToFit:false,
	                    sortname:'userid',
	                    sortorder:'desc',
	                    viewrecords:true,
	                    multiselect: true, // 是否显示复选框
	                    multiboxonly : true, 
	                    rownumbers: false,//显示行号
	                    editable:true, 
	                    rowNum:<%=session.getAttribute("SYS_PAGECOUNT")%>,
	                    rowList:[15,20,50,200,500],
	                    toolbar: [false,"top"],
	                    jsonReader: {
	                        root:"rows",        // 数据行（默认为：rows）
	                        page: "page",   // 当前页
	                        total: "total",  // 总页数
	                        records: "records",  // 总记录数
	                        repeatitems : false     // 设置成false，在后台设置值的时候，可以乱序。且并非每个值都得设
	                    },
	                    prmNames:{rows:"rows",page:"page",sort:"sidx",order:"sord",search:"search"},
	                    pager:"#gridPagerUsers",
	                    caption: "组织下的用户查看"
	                });
	                 jQuery("#gridTableUsers").jqGrid('navGrid','#gridPagerUsers',{add:false,edit:false,del:false,search:false,refresh:false});
	                    
			    });
                //执行大小
                function doResize() { 
                  var ss = getPageSize(); 
                  $("#gridTableOrganization").jqGrid('setGridHeight', ss.WinH-140);              
                } 
                //刷新
                function refresh(){
                  reset();
                  gridSearch();
                }
    
			//-----------------------------------
			<%
				ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(application);
     			OrganizationAction organization = (OrganizationAction)context.getBean("organizationAction");
				List result = organization.getOrganizationTree();
				String treeNode = "";
				String orgParentId = "";
				String orgId = "" ;
				String orgName = "";
				String orgNo = "";
				String orgDesc = "";
				String departmentAs = "";
				String orgPrex = "";
				Long orgOrder;
				//
				String unitAptitude="";
				String unitLevel="";
				String unitAddr="";
				String unitPostcode="";
				String unitStandard="";
				String unitType="";
				for(int i=0;i<result.size();i++){
					Organization o = (Organization)result.get(i);
					orgId = o.getOrgId().toString();
					orgNo = (String)o.getOrgNo();
					orgName = (String)o.getOrgName();
					orgDesc = (String)o.getOrgDesc();
					departmentAs = (String)o.getDepartmentAs();
					orgParentId = o.getOrgParentId().toString();
					orgDesc =(String)o.getOrgDesc();
					//orgDesc = o.getOrgDesc()==null?"":o.getOrgDesc();
					orgOrder = o.getOrgOrder();
					orgPrex = o.getOrgPrex();
					
					unitAptitude=(String)o.getUnitAptitude();
					unitLevel=(String)o.getUnitLevel();
					unitAddr=(String)o.getUnitAddr();
					unitPostcode=(String)o.getUnitPostcode();
					unitStandard=(String)o.getUnitStandard();
					unitType=(String)o.getUnitType();
					if("1".equals(orgId)){
						/*treeNode +="{\"id\":"+orgId+",\"pId\":"+orgParentId+",\"no\":\""+
						orgNo+"\",\"name\":\""+orgName+"\",\"title\":\""+orgDesc+
						"\",\"departmentAs\":\""+departmentAs+
						"\",\"open\":true,\"orgOrder\":\""+orgOrder+
						"\",\"orgPrex\":\""+orgPrex+"\"},";	*/
						treeNode +="{\"id\":"+orgId+",\"pId\":"+orgParentId+",\"no\":\""+
						orgNo+"\",\"name\":\""+orgName+"\",\"title\":\""+orgDesc+
						"\",\"departmentAs\":\""+departmentAs+
						"\",\"open\":true,\"orgOrder\":\""+orgOrder+
						"\",\"orgPrex\":\""+orgPrex+"\",\"unitAddr\":\""+unitAddr+
						"\",\"unitPostcode\":\""+unitPostcode+
						"\",\"unitStandard\":\""+unitStandard+
						"\",\"unitAptitude\":\""+unitAptitude+
						"\",\"unitLevel\":\""+unitLevel+
						"\",\"unitType\":\""+unitType+"\"},";	
					}else{
						/*treeNode +="{\"id\":"+orgId+",\"pId\":"+orgParentId+",\"no\":\""+
						orgNo+"\",\"name\":\""+orgName+"\",\"title\":\""+orgDesc+
						"\",\"departmentAs\":\""+departmentAs+
						"\",\"open\":false,\"orgOrder\":\""+orgOrder+
						"\",\"orgPrex\":\""+orgPrex+"\"},";	*/
						
						treeNode +="{\"id\":"+orgId+",\"pId\":"+orgParentId+",\"no\":\""+
						orgNo+"\",\"name\":\""+orgName+"\",\"title\":\""+orgDesc+
						"\",\"departmentAs\":\""+departmentAs+
						"\",\"open\":false,\"orgOrder\":\""+orgOrder+
						"\",\"orgPrex\":\""+orgPrex+"\",\"unitAddr\":\""+unitAddr+
						"\",\"unitPostcode\":\""+unitPostcode+
						"\",\"unitStandard\":\""+unitStandard+
						"\",\"unitAptitude\":\""+unitAptitude+
						"\",\"unitLevel\":\""+unitLevel+
						"\",\"unitType\":\""+unitType+"\"},";
					}
					
				}
				String newTreeNode=treeNode.substring(0,treeNode.length()-1);	
			%>
			var setting = {
				treeId:'tree',
				callback: {
						onClick: zTreeOnClick,
						beforeCollapse: beforeCollapse,
						beforeExpand: beforeExpand,
						onCollapse: onCollapse,
						onExpand: onExpand
					},
				view: {
					selectedMulti: false
				},
				data: {
					key: {
						title: "name"
					},
					simpleData: {
						enable: true,
						idKey: "id",
						pIdKey: "pId",
						rootPId: -1
					}
								
				},
				view: {
					fontCss: getFontCss
				}
			};
			function zTreeOnClick(event, treeId, treeNode) {
			    //alert(treeNode.id + ", " + treeNode.name+","+treeNode.pId);
			     old = treeNode.no;
			    tree_sel = treeNode;
			   /* var id=treeNode.id;
			    var name = treeNode.name;
			    var no = treeNode.no;
			    var title = treeNode.title;
			    var departmentAs = treeNode.departmentAs;
			    var pId = treeNode.pId;*/
			    
			    var id="";
			    var name = "";
			    var no = "";
			    var title = "";
			    var departmentAs = "";
			    var pId = "";
			    		
			    var unitAptitude = "";
			    var unitLevel = "";
			    var unitAddr = "";
			    var unitPostcode =""; 
			    var unitStandard = "";
			    var unitType = "";
			    
			    var orgOrder = ""
			    var orgPrex = "";
			    
			     if (treeNode.id!="null"){
			    	id = treeNode.id;
			    }	
			     if (treeNode.name!="null"){
			    	name = treeNode.name;
			    }	
			     if (treeNode.no!="null"){
			    	no = treeNode.no;
			    }	
			     if (treeNode.title!="null"){
			    	title = treeNode.title;
			    }	
			     if (treeNode.departmentAs!="null"){
			    	departmentAs = treeNode.departmentAs;
			    }	
			     if (treeNode.pId!="null"){
			    	pId = treeNode.pId;
			    }	
			    
			    if (treeNode.orgOrder!="null"){
			    	orgOrder = treeNode.orgOrder;
			    }			  
			    
			    if (treeNode.orgPrex!="null"){
			    	orgPrex = treeNode.orgPrex;
			    }
			    
			    if (treeNode.unitAptitude!="null"){
			    	unitAptitude=treeNode.unitAptitude;
			    }
			    if (treeNode.unitLevel!="null"){
			    	unitLevel=treeNode.unitLevel;
			    }
			    if (treeNode.unitAddr!="null"){
			    	unitAddr=treeNode.unitAddr;
			    }
			    if (treeNode.unitPostcode!="null"){
			    	unitPostcode=treeNode.unitPostcode;
			    }
			    if (treeNode.unitStandard!="null"){
			    	unitStandard=treeNode.unitStandard;
			    }
			     if (treeNode.unitType!="null"){
			    	unitType=treeNode.unitType;
			    }
			    
			    if (treeNode.id!="null"){
			    	id = treeNode.id;
			    }	
			     if (treeNode.name!="null"){
			    	name = treeNode.name;
			    }	
			     if (treeNode.no!="null"){
			    	no = treeNode.no;
			    }	
			     if (treeNode.title!="null"){
			    	title = treeNode.title;			    	
			    }					    
			     if (treeNode.departmentAs!="null"){
			    	departmentAs = treeNode.departmentAs;
			    }	
			     if (treeNode.pId!="null"){
			    	pId = treeNode.pId;
			    }	
			    
			    if (treeNode.orgOrder!="null"){
			    	orgOrder = treeNode.orgOrder;
			    }			  
			    
			    if (treeNode.orgPrex!="null"){
			    	orgPrex = treeNode.orgPrex;
			    }
			    
			    if (treeNode.unitAptitude!="null"){
			    	unitAptitude=treeNode.unitAptitude;
			    }
			    if (treeNode.unitLevel!="null"){
			    	unitLevel=treeNode.unitLevel;
			    }
			    if (treeNode.unitAddr!="null"){
			    	unitAddr=treeNode.unitAddr;
			    }
			    if (treeNode.unitPostcode!="null"){
			    	unitPostcode=treeNode.unitPostcode;
			    }
			    if (treeNode.unitStandard!="null"){
			    	unitStandard=treeNode.unitStandard;
			    }
			    if (treeNode.unitType!="null"){
			    	unitType=treeNode.unitType;
			    }
			    
			    document.getElementById("orgName").value = name;
			    document.getElementById("orgNo").value = no;
			    //document.getElementById("orgDesc").value = title;
	
			    document.getElementById("unitAptitude").value = unitAptitude;
			    document.getElementById("unitLevel").value = unitLevel;			   
			    document.getElementById("unitAddr").value = unitAddr;		   
			    document.getElementById("unitPostcode").value = unitPostcode;
			    document.getElementById("unitStandard").value = unitStandard;
			    document.getElementById("unitType").value = unitType;
			    
			  var defaultval="def";
			    /*if(treeNode.orgDesc == 'null'||title==''){
				    document.getElementById("orgDesc").value  = defaultval;
				}else{
					document.getElementById("orgDesc").value = title;
				}
			    if(treeNode.departmentAs == 'null'){
				    document.getElementById("departmentAs").value  = "";
				}else{
					document.getElementById("departmentAs").value = departmentAs;
				}
			    document.getElementById("orgId").value = id;
			    document.getElementById("pId").value = pId;
			    document.getElementById("orgOrder").value = orgOrder;
			    document.getElementById("orgPrex").value = orgPrex;
			    */
			    flag = "2";
			    chaflag = "1";
			    delflag = "1";
			    orgParentId = id;
			    jQuery("#gridTableOrganization").jqGrid('setGridParam',
					{
						url:common_contextPath+'/organization/queryOrganization.action?flag=2&id='+id
					}).trigger("reloadGrid", [{page:1}]);
			    jQuery("#gridTableUsers").jqGrid('setGridParam',
					{
						url:common_contextPath+'/organization/searchUsers.action?id='+id
					}).trigger("reloadGrid", [{page:1}]);
			    
			    	document.getElementById('gengxinBtn').style.display=""; 
			    	document.getElementById("orgName").readOnly=false;
			    	document.getElementById("orgNo").readOnly=false;
			    	//document.getElementById("orgDesc").readOnly=false;
			    	//document.getElementById("departmentAs").readOnly=false;
			};
			
			/**
			 * 功能描述：组织管理------添加功能
			 */
			function addOrganization(){
				if(tree_sel==null){
						alert("请选择相应节点进行添加");
				}else{
					$.dialog({
				        id:'cerify',
				        data:"{'orgParentId':"+tree_sel.id+",'orgParentIdsName':'"+tree_sel.name+"','orgNo':'"+tree_sel.no+"'}",
				        title:'组织机构添加', 
				        content:'url:<%=request.getContextPath() %>/system/organizationadd.jsp',
				        okVal:false,//确定按钮文字
				        cancelVal:false,//取消按钮文字
				        min:true, //是否显示最小化按钮
				        max:false,//是否显示最大化按钮
				        fixed:false,//开启静止定位
				        lock:true,//开启锁屏
				        focus:true,//弹出窗口后是否自动获取焦点（4.2.0新增）
				        time:null,//设置对话框显示时间
				        resize:true,//是否允许用户调节尺寸
				        drag:true,//是否允许用户拖动位置
				        cache:false,//是否缓存iframe方式加载的窗口内容页
				        width: '500px',
				        height: 600,
				        close: function(){
				        	location.reload();   
				        }
	        		});
				}
				
			}
			/**
			 * 功能描述：组织管理------修改功能
			 */
			function updateOrganization(){
				if(tree_sel==null){
					alert("请选择相应节点进行修改");
				}else if(tree_sel.pId == -1){
					alert("根节点不允许修改");
				}else{
					$.dialog({
			        id:'cerify',
			        data:"{'orgParentId':"+tree_sel.getParentNode().id+
			        ",'orgParentIdsName':'"+tree_sel.getParentNode().name+
			        "','orgId':'"+tree_sel.id+"','orgNo':'"+tree_sel.no+
			        "','orgName':'"+tree_sel.name+"','orgDesc':'"+
			        tree_sel.title+
			        "','unitAptitude':'"+tree_sel.unitAptitude+
			        "','unitLevel':'"+tree_sel.unitLevel+
			        "','unitAddr':'"+tree_sel.unitAddr+
			        "','unitPostcode':'"+tree_sel.unitPostcode+
			        "','unitType':'"+tree_sel.unitType+
			        "','unitStandard':'"+tree_sel.unitStandard+
			        "','departmentAs':'"+tree_sel.departmentAs+"'}",
			        title:'组织机构修改', 
			        content:'url:<%=request.getContextPath() %>/system/organizationupdate.jsp',
			        okVal:false,//确定按钮文字
			        cancelVal:false,//取消按钮文字
			        min:true, //是否显示最小化按钮
			        max:false,//是否显示最大化按钮
			        fixed:false,//开启静止定位
			        lock:true,//开启锁屏
			        focus:true,//弹出窗口后是否自动获取焦点（4.2.0新增）
			        time:null,//设置对话框显示时间
			        resize:true,//是否允许用户调节尺寸
			        drag:true,//是否允许用户拖动位置
			        cache:false,//是否缓存iframe方式加载的窗口内容页
			        width: '460px',
			        height: 600,
			        close: function(){
			        	location.reload();   
			        }
	        	});
				}
				
			}
			
			function updateTab1(){
				$('#pageFrom input').keyup(trimkeyup);
					//验证是否为空 及是否存在 特殊字符
				/*if($.trim($("#orgNo").val()) == ""){
					alert("请填写组织机构编号!");
					$("#orgNo").focus();
					return false;
					}*/
				if($.trim($("#orgNo").val()) != "")
				{
					if(!checkExp2($("#orgNo").val())){
						alert("组织机构编号不能含有如下特殊符号：\" # $ \, \' \\ \{");
						$("#orgNo").focus();
						return false;
					}else if(!orgNoCountintlen($("#orgNo").val())){
						alert("组织机构编号最多为40个字符,字符输入超出限制!");
						$("#orgNo").focus();
						return false;
					}else if(!(flag = checkorgNo())){
						$("#orgNo").focus();
						return false;
					}
				}
				
				
				if($.trim($("#orgName").val()) == ""){
					alert("请填写组织机构名称!");
					$("#orgName").focus();
					return false;
				}else if(!checkExp2($("#orgName").val())){
					alert("组织机构名称不能含有如下特殊符号：\" # $ \, \' \\ \{");
					$("#orgName").focus();
					return false;
				}else if(!orgNameCountintlen($("#orgName").val())){
					alert("组织机构名称最多为40个字符,字符输入超出限制!");
					$("#orgName").focus();
					return false;
				}
				
				if(!checkExp1($("#departmentAs").val())){
					alert("组织机构简称不能含有如下特殊符号：\" # $ \, \' \\");
					$("#departmentAs").focus();
					return false;
				}else if(!departmentAsCountintlen($("#departmentAs").val())){
					alert("组织机构简称最多为40个字符,字符输入超出限制!");
					$("#departmentAs").focus();
					return false;
				}
				
				if(!checkExp1($("#orgDesc").val())){
					alert("组织机构说明不能含有如下特殊符号：\" # $ \, \' \\");
					$("#orgDesc").focus();
					return false;
				}else if(!orgDescCountintlen($("#orgDesc").val())){
					alert("组织机构说明最多为40个字符,字符输入超出限制!");
					$("#orgDesc").focus();
					return false;
				}
				
				var orgId = document.getElementById("orgId").value;
				var  pId= document.getElementById("pId").value;
				var  orgNo= document.getElementById("orgNo").value;
				var  orgName= document.getElementById("orgName").value;
				var  orgDesc= document.getElementById("orgDesc").value;
				var  orgOrder= document.getElementById("orgOrder").value;
				var  departmentAs= document.getElementById("departmentAs").value;
				var  orgPrex= document.getElementById("orgPrex").value;
				var  orgParentIdsName="";
				if(tree_sel.id != 1){
					orgParentIdsName= tree_sel.getParentNode().name;
				}
				var params = {  
					"orgParentIdsName":orgParentIdsName,
			        "orgId": orgId,
			        "pId": pId,
			        "orgNo": orgNo,
			        "orgName": orgName,
			        "departmentAs": departmentAs,
			        "orgDesc": orgDesc,
			        "orgOrder": orgOrder,
			        "orgPrex": orgPrex
				 };  

				var actionUrl = "updateOrg.action";  
			    $.ajax({  
			        url : actionUrl,  
			        type : "post", 
			        data : params,  
			        dataType : "json",  
			        cache : false,  
			    error : function(textStatus, errorThrown) {  
			        alert("系统ajax交互错误: " + textStatus.value);  
			    },  
			    success : function(data, textStatus) {  
			    	//alert(data.ajaxResult);
	            	if(data.ajaxResult=='success'){
		        		alert("更新成功！");    
		        		tree_sel.name = orgName; 
		        		tree_sel.no = orgNo;
		        		tree_sel.title = orgDesc;
		        		tree_sel.departmentAs = departmentAs;
						treeObj.updateNode(tree_sel);
		        	}else if(data.ajaxResult=='have'){
		        		alert(tree_sel.getParentNode().name+"下已存在该组织机构名称");
		        		$("#orgName").focus();
		        	}else if(data.result=='haveChild'){
		    	      	alert("与子节点的组织机构名称重复");
		    	    	$("#orgName").focus();
		    	      }else if (data.ajaxResult=='haveparent'){
		    	    	  alert("与父节点的组织机构名称重复");
		    	    	  $("#orgName").focus();
		    	      }  
			    }  
	           });
			}
			//验证input长度
			function orgNoCountintlen(input){
				var result = $("#orgNo").val().length;
				if (result > 40) {
					return false;
				}else{
					return true;
				}
			}
			function orgNameCountintlen(input){
				var result = $("#orgName").val().length;
				if (result > 40) {
					return false;
				}else{
					return true;
				}
			}
			function orgDescCountintlen(input){
				var result = $("#orgDesc").val().length;
				if (result > 40) {
					return false;
				}else{
					return true;
				}
			}
			//验证特殊字符
			function checkExp(inputData){ 
				//var regEx = new RegExp(/^(([^\^\.<>%&',:;=?$"'#@!~\]\[{}【】￥（）！·‘’”“。，、？：；—|\/\\/`\|])*)$/);
				var regEx = new RegExp(/^(([^$,"'#])*)$/);
				var result = inputData.match(regEx);
				if (result == null) {
				return false;
				}
				return true;
			}
			 //验证唯一性
		    function checkorgNo(){
				var flag = true;
				
				$.ajax({
				   type: "POST",
				   async: false,//取消异步提交
				   url: "findOrganizationByorgNo.action",
				   dataType: "json",
				   data: {
				   		orgNo: function(){
							return encodeURIComponent(document.getElementById("orgNo").value);
						},
						old:encodeURIComponent(old)
				   },
				   success: function(data){
				   	 if(data.result != "success"){
				     	alert( "已存在该组织机构编号" );
				     	flag = false;
				     }
				   }
				}); 
				return flag;
			}
			//验证特殊字符
			function checkExp1(inputData){ 
				//var regEx = new RegExp(/^(([^\^\.<>%&',:;=?$"'#@!~\]\[{}【】￥（）！·‘’”“。，、？：；—|\/\\/`\|])*)$/);
				var regEx = new RegExp(/^(([^$,"'#\\])*)$/);
				var result = inputData.match(regEx);
				if (result == null) {
				return false;
				}
				return true;
			}
			//验证特殊字符
			function checkExp2(inputData){ 
				var regEx = new RegExp(/^(([^$,#"'{\\])*)$/);
				var result = inputData.match(regEx);
				if (result == null) {
				return false;
				}
				return true;
			}
		    //验证唯一性
		    function checkorgNo(){
				var flag = true;
				
				$.ajax({
				   type: "POST",
				   async: false,//取消异步提交
				   url: "findOrganizationByorgNo.action",
				   dataType: "json",
				   data: {
				   		orgNo: function(){
							return encodeURIComponent(document.getElementById("orgNo").value);
						},
						old:encodeURIComponent(old)
				   },
				   success: function(data){
				   	 if(data.result != "success"){
				     	alert( "已存在该组织机构编号!" );
				     	flag = false;
				     }
				   }
				}); 
				return flag;
			}
			//过滤表单的前后空格
			function trimkeyup(e) {
			     lucene_objInput = $(this);
			     if (e.keyCode != 38 && e.keyCode != 40 && e.keyCode != 13) {
			        var im = $.trim(lucene_objInput.val());
			       lucene_objInput.val(im); 
			    }
			} 
			function departmentAsCountintlen(input){
				var result = $("#departmentAs").val().length;
				if (result > 40) {
					return false;
				}else{
					return true;
				}
			}
			/**
			 * 功能描述：组织管理------删除功能
			 */
			function deleteOrganization(){
				    
				   if(tree_sel == null){
						alert("请选择节点进行删除");
					}else if(tree_sel.pId != -1){
						var treeObj = $.fn.zTree.getZTreeObj("tree");
						var delIds = [];
						var id = tree_sel.id;
						var nodeId = tree_sel.id;
						var nodeName= tree_sel.name;
						if(treeObj.getNodeByParam("id", nodeId, null).isParent){
							alert(nodeName+"不是子节点,请选择其子节点依次删除");
							return;
						}else{
							if(!confirm("是否确认删除 ？")){
								return false;
							}
							delIds.push(nodeId);
						}
						var nodeName= tree_sel.name;
						var actionUrl = "removeOrganization.action?delflag=2&ids="+tree_sel.id;  
						    $.ajax({  
						        url : actionUrl,  
						        type : "post", 
						        //data : params,  
						        dataType : "json",  
						        cache : false,  
						    error : function(textStatus, errorThrown) {  
						        alert("系统ajax交互错误: " + textStatus.value);  
						    },  
						    success : function(data, textStatus) {  
				            	if(data.ajaxResult=='success'){
					        		alert("删除成功！");       
					        		location.reload();   
					        	}else if(data.ajaxResult=='have'){
					        		alert(nodeName+"组织下有所属人员，不能删除!");     
					        	}else if(data.ajaxResult=='haveoneorganization'){
					        		alert(nodeName+"该数据被调用,不能删除!");     
					        	}else if(data.ajaxResult=='error'){
					        		alert("删除失败！");       
					        	}
						    }  
				        });
					}else if(tree_sel.pId == -1){
						
							alert("根节点不允许删除");
					
					}
			}
			var zNodes =[
					<%=newTreeNode%>
			];
		
			function showIconForTree(tetid, treeNode) {
				return !treeNode.isParent;
			};
			//展开/关闭按钮 开始-----------------------------------------------------------------------
			var log, className = "dark";
			function beforeCollapse(treeId, treeNode) {
				className = (className === "dark" ? "":"dark");
				showLog("[ "+getTime()+" beforeCollapse ]&nbsp;&nbsp;&nbsp;&nbsp;" + treeNode.name );
				return (treeNode.collapse !== false);
			}
			function onCollapse(event, treeId, treeNode) {
				showLog("[ "+getTime()+" onCollapse ]&nbsp;&nbsp;&nbsp;&nbsp;" + treeNode.name);
			}		
			function beforeExpand(treeId, treeNode) {
				className = (className === "dark" ? "":"dark");
				showLog("[ "+getTime()+" beforeExpand ]&nbsp;&nbsp;&nbsp;&nbsp;" + treeNode.name );
				return (treeNode.expand !== false);
			}
			function onExpand(event, treeId, treeNode) {
				showLog("[ "+getTime()+" onExpand ]&nbsp;&nbsp;&nbsp;&nbsp;" + treeNode.name);
			}
			function showLog(str) {
				if (!log) log = $("#log");
				log.append("<li class='"+className+"'>"+str+"</li>");
				if(log.children("li").length > 8) {
					log.get(0).removeChild(log.children("li")[0]);
				}
			}
			function getTime() {
				var now= new Date(),
				h=now.getHours(),
				m=now.getMinutes(),
				s=now.getSeconds(),
				ms=now.getMilliseconds();
				return (h+":"+m+":"+s+ " " +ms);
			}
	
			function expandNode(e) {
				var zTree = $.fn.zTree.getZTreeObj("tree"),
				type = e.data.type,
				nodes = zTree.getSelectedNodes();
				if (type.indexOf("All")<0 && nodes.length == 0) {
					alert("请先选择一个父节点");
				}
	
				if (type == "expandAll") {
					zTree.expandAll(true);
				} else if (type == "collapseAll") {
					zTree.expandAll(false);
				} else {
					var callbackFlag = $("#callbackTrigger").attr("checked");
					for (var i=0, l=nodes.length; i<l; i++) {
						zTree.setting.view.fontCss = {};
						if (type == "expand") {
							zTree.expandNode(nodes[i], true, null, null, callbackFlag);
						} else if (type == "collapse") {
							zTree.expandNode(nodes[i], false, null, null, callbackFlag);
						} else if (type == "toggle") {
							zTree.expandNode(nodes[i], null, null, null, callbackFlag);
						} else if (type == "expandSon") {
							zTree.expandNode(nodes[i], true, true, null, callbackFlag);
						} else if (type == "collapseSon") {
							zTree.expandNode(nodes[i], false, true, null, callbackFlag);
						}
					}
				}
			}
			//展开/关闭按钮  结束---------------------------------------------------------------------
			$(document).ready(function(){
				treeObj = $.fn.zTree.init($("#tree"), setting, zNodes);
				$("#expandAllBtn").bind("click", {type:"expandAll"}, expandNode);
				$("#collapseAllBtn").bind("click", {type:"collapseAll"}, expandNode);
				
			}); 
			 //查看
			function searchOrganization(){
				 var ids= $("#gridTable").jqGrid("getGridParam", "selarrrow") + "";
				 if(ids){
					 chaflag=2;
					 if(ids.indexOf(",")!=-1){
						  alert("只能选择一条记录!");  
					        return false; 
					 }
				     var row = jQuery("#gridTable").jqGrid('getRowData',ids);//获取选中行.
					 var id = row.ORG_ID;//获取选中行的id属性
					 var viewSend = 'searchOrganization.action?id='+id;
					
					 openModalDialog(viewSend,'500px','200px'); // 模式对话框的效果
					 
				 }else{
					 if(tree_sel==null){
						alert("请选择相应节点进行查看");
					 }
					 id=tree_sel.id;
					 var viewSend = 'searchOrganization.action?id='+id;
			    	 openModalDialog(viewSend,'500px','200px'); // 模式对话框的效果
				 }
			}
			</script>
	<style type="text/css">
		 body{background:#ffffff; background-image:url(images/);}
	   		html{   
			    overflow-x: hidden; 
				overflow-y: hidden;
				}  		
    </style>
	</head>
	<body >
		<form id="pageFrom" action="" name="" method="post">
		<table width="100%"  border="0" cellpadding="0" cellspacing="0">
			<tr>
  <td height="379" width="260" valign="top" style="background: #FFFFFF; border: #aaaaaa solid 1px;">
  <div style="font-size:13px;height:30px;padding-top:5px;padding-left:5px;background-image: url(../images/tree_l_sc_bg.gif);background-repeat:repeat-x;">组织名称检索：
						<input type="text" id="key" name="organization.orgName" value="" class="empty" style="width:150px; height:16px; line-height:20px;"  />
					</div>
					  <!--
					  <div style="font-size:13px;height:30px;padding-top:5px; text-align:center;background-image: url(../images/tree_l_sc_bg.gif);background-repeat:repeat-x;">		               
					    --> 
					 <div style="font-size:13px;height:30px;padding-top:55px; text-align:center;background-image: url(../images/tree_l_sc_bg.gif);background-repeat:repeat-x;">	
	               
					<input id="add" type="button" class="button_b" onclick="addOrganization()" name="Submit4" value="添加" style="width: 70px"/>
					<input id="update" type="button" class="button_b" onclick="updateOrganization()" name="Submit4" value="修改" style="width: 70px"/>
					<input id="delete" type="button" class="button_b" onclick="deleteOrganization()" name="Submit4" value="删除" style="width: 70px"/>
					</div>
					<!-- 
					 <div style="background-image: url(<%=request.getContextPath() %>/jslib/ztree/img/titlie.gif); background-repeat:repeat-x;height: 20px; width: 100%; padding-top:5px;">
					 -->
					 <div style="background-image: url(<%=request.getContextPath() %>/jslib/ztree/img/titlie.gif); background-repeat:repeat-x;height: 20px; width: 100%; padding-top:20px;">
						<span>
						    <img onclick="return false;"  src="../jslib/ztree/img/add.png" alt="展开" title="点击展开所有节点"  id="expandAllBtn"/>
						</span>
						<span >
							<img onclick="return false;" src="../jslib/ztree/img/delete.gif"  alt="闭合" title="点击关闭所有节点" id="collapseAllBtn"/>
						</span>	
					</div>
					<!-- <div style="WIDTH: 260px; HEIGHT: 480px; OVERFLOW: auto; scrollbar-3dlight-color: #595959; scrollbar-arrow-color: #FFFFFF; scrollbar-base-color: #CFCFCF;scrollbar-darkshadow-color:#FFFFFF; scrollbar-face-color: #CFCFCF; scrollbar-highlight-color: #FFFFFF; scrollbar-shadow-color: #595959"> -->
						<div style="WIDTH: 260px; HEIGHT: 400px; OVERFLOW: auto; scrollbar-3dlight-color: #595959; scrollbar-arrow-color: #FFFFFF; scrollbar-base-color: #CFCFCF;scrollbar-darkshadow-color:#FFFFFF; scrollbar-face-color: #CFCFCF; scrollbar-highlight-color: #FFFFFF; scrollbar-shadow-color: #595959">
						<div id="treeList" class="dtree">
							<!-- <ul id="tree" class="ztree" style="width:230px; overflow:auto;"></ul> -->
							<ul id="tree" class="ztree" style="width:230px; "></ul>
						</div>
					</div>
				</td>
				<td valign="top"  style="padding-left:10px;background-color:#eaeaea;">
					<table width="100%" border="0" cellpadding="0" cellspacing="0">
						<tr>
							<td >					
								<div id="tabs" style="height:600px;"> 
									<ul style="border-top:0px;border-left:0px;border-right:0px;"> 
									<li><a href="#tab-1">组织基本信息</a></li> 
									<li><a href="#tab-2">下属组织</a></li> 
									<li><a href="#tab-3">组织下人员</a></li> 
									</ul> 
									<div id="tab-1">
										    <input type="hidden" id="orgId" name="orgId"/>
										    <input type="hidden" id="pId" name="pId"/>
											<table width="500" border="0" align="center" cellpadding="5" cellspacing="5" class="formTableNew">
											  <tr>
											    <td align="right">组织机构编号：</td>
											    <td> 
												    <div class="div">
														<input id="orgNo" name="orgNo"   style="width:215px"/>
										                <!--  <img src="<%=request.getContextPath() %>/images/xh.png"></img> -->
													</div>
											    </td>
											  </tr>
										      <tr>
										        <!-- <td align="right">组织机构名称：</td> -->
											    <td align="right">单位名称：</td>
											    <td> 
												    <div class="div">
														<input id="orgName" name="orgName" style="width:215px"></input>
														<!-- <input id="orgName" name="orgName" value="四川成发航空科技股份有限公司" readonly="readonly" style="width:215px"/> -->
														<img src="<%=request.getContextPath() %>/images/xh.png"></img>
													</div>
											    </td>
											  </tr>
											   <tr>
											    <td align="right">单位资质：</td>
											    <td> 
												    <div class="div">
														<input id="unitAptitude" name="unitAptitude"  style="width:215px"></input>
													</div>
											    </td>
											  </tr>
											   <tr>
											    <td align="right">资质等级：</td>
											    <td> 
												    <div class="div">
														<input id="unitLevel" name="unitLevel"  style="width:215px"></input>
													</div>
											    </td>
											  </tr>
											   <tr>
											    <td align="right">单位地址：</td>
											    <td> 
												    <div class="div">
														<input id="unitAddr" name="unitAddr"  style="width:215px"></input>
													</div>
											    </td>
											  </tr>
											   <tr>
											    <td align="right">邮政编码：</td>
											    <td> 
												    <div class="div">
														<input id="unitPostcode" name="unitPostcode"  style="width:215px"></input>
													</div>
											    </td>
											  </tr>
											   <tr>
											    <td align="right">单位规范：</td>
											    <td> 
												    <div class="div">
														<input id="unitStandard" name="unitStandard"  style="width:215px"></input>
													</div>
											    </td>
											  </tr>		
											   <tr>
											    <td align="right">单位类别：</td>
											    <td> 
												    <div class="div">
														<input id="unitType" name="unitType"  style="width:215px"></input>
													</div>
											    </td>
											  </tr>				
											  <!-- 
										      <tr>
											    <td align="right">组织机构简称：</td>
											    <td> 
												    <div class="div">
														<input id="departmentAs" name="departmentAs"  style="width:215px"></input>
													</div>
											    </td>
											  </tr>
											  <tr>
											    <td align="right">组织机构说明：</td>
											    <td>
											    	<div class="div">
														<input id="orgDesc" name="orgDesc"  style="width:215px"/>
													</div>	
											    </td>
											  </tr>
											  <tr>
											    <td align="right">组织机构排序：</td>
											    <td>
											    	<div class="div">
														<input id="orgOrder" name="orgOrder" style="width:215px"/>
													</div>	
											    </td>
											  </tr>
											  <tr>
											    <td align="right">组织机构前缀：</td>
											    <td>
											    	<div class="div">
														<input id="orgPrex" name="orgPrex" style="width:215px"/>
													</div>	
											    </td>
											  </tr>
											   -->
								              <tr>
								            	<td align="center" colspan="2" >
													<input type="button"  id="gengxinBtn" value="更 新" onclick="updateTab1()" style="display: none" class="form_bt_orange" />
												</td>
								        	  </tr>
								      </table>
									</div> 
									<div id="tab-2" style="padding:8px;">
									    <table class="tableCont" style="width:100%;">
									            <tr>
									                <td colspan="4">
									                    <table id="gridTableOrganization"></table>
									                    <div id="gridPagerOrganization"></div>
									                </td>
									            </tr>
									    </table>
									</div> 
									<div id="tab-3" style="padding:8px;">
									    <table class="tableCont" style="width:100%;">
									            <tr>
									                <td colspan="4">
									                    <table id="gridTableUsers"></table>
									                    <div id="gridPagerUsers"></div>
									                </td>
									            </tr>
									    </table>
									</div> 
								</div> 
							</td>
						</tr>
				  </table>
				</td>
		  </tr>
		</table>
		</form>
	</body>
</html>
